package website.haicheng.picturemanage.commo.util;

import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import website.haicheng.picturemanage.commo.exceptions.ConstraintNotMatchException;

import java.util.Collection;
import java.util.Objects;

/**
 * @author haicheng.long@androidmov.com
 * @ClassName Assert
 * @Description 断言工具类
 * @date 2020/11/6 下午 3:35
 */
public class Assert extends org.springframework.util.Assert {
    /**
     * 对象不可为空
     *
     * @param o       被验证对象
     * @param message 提示消息
     */
    public static void notNull(Object o, String message) {
        if (Objects.isNull(o)) {
            throw new ConstraintNotMatchException(message);
        }
    }

    /**
     * 校验字符串是否为空
     *
     * @param str    str
     * @param messge messge
     */
    public static void notBlack(String str, String messge) {
        if (!StringUtils.hasLength(str)) {
            throw new ConstraintNotMatchException(messge);
        }
    }

    /**
     * 集合不为空断言
     *
     * @param collection collection
     * @param message    message
     */
    public static void collectionNotEmpty(Collection<?> collection, String message) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new ConstraintNotMatchException(message);
        }
    }

    /**
     * @param stat:
     * @param message:
     * @description: boolean断言
     * @author: haicheng.long@androidmov.com
     * @date: 2020/7/25 下午 2:07
     * @return: void
     **/
    public static void stat(boolean stat, String message) {
        if (stat) {
            throw new ConstraintNotMatchException(message);
        }
    }

}